package game.towers;

import game.scenario.Wave;

import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.event.MouseEvent;

import utils.Properties;
import core.rendering.RenderableMouse;

public class TowerMatrix extends RenderableMouse {

	SimpleTower data[][];
	Wave units;

	public TowerMatrix(int xsize, int ysize, int xpos, int ypos) {
		super(xpos, ypos);
		data = new SimpleTower[xsize][ysize];

		for (int cont = 0; cont < data.length; cont++) {
			for (int cont2 = 0; cont2 < data[cont].length; cont2++) {
				data[cont][cont2] = null;
			}
		}
	}

	public void addTower(int xpos, int ypos) {
		if (canAddTower(xpos, ypos)) {
			SimpleTower t = new SimpleTower(xpos * Properties.TILE_WIDTH +16, ypos
					* Properties.TILE_HEIGHT + 16);
			data[xpos][ypos] = t;
		}
	}

	public boolean canAddTower(int xpos, int ypos) {
		if (xpos < data.length && ypos < data[0].length) {

			return data[xpos][ypos] == null;
		} else {
			return false;
		}
	}

	@Override
	public boolean onClick(MouseEvent e) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void updateMouse(Point p) {
		// TODO Auto-generated method stub

	}

	@Override
	public void renderComponent(Graphics2D g2d) {
		// TODO Auto-generated method stub
		for (int cont = 0; cont < data.length; cont++) {
			for (int cont2 = 0; cont2 < data[cont].length; cont2++) {
				if (data[cont][cont2] != null) {
					data[cont][cont2].render(g2d);
				}
			}
		}
	}

	@Override
	public void updateLogic() {
		// TODO Auto-generated method stub
		for (int cont = 0; cont < data.length; cont++) {
			for (int cont2 = 0; cont2 < data[cont].length; cont2++) {
				if (data[cont][cont2] != null) {
					data[cont][cont2].updateLogic();
					data[cont][cont2].doAttack(units);
				}
			}
		}
	}

	public void setWave(Wave w) {
		units = w;
	}

	public Wave getWave() {
		return units;
	}

}
